_package("caf.ui");

_import("alz.core.Animation");
_import("alz.mui.Component");
_import("caf.ui.Button");
_import("caf.ui.TabBar");
/**
 * 滚动条组件
 */
_class("TabPanel", Component, function(){
	this._init = function(){
		_super._init.call(this);
		this._animation = null;
		this._conf = null;
		this._btn = null;
		this._childConf = null;
		this._tabbar = null;
		this._activeItem = null;
	};
	this.create = function(parent){
		//var obj = this.createElement(parent, "div", "scrollbar");
		//this.init(obj);
		//return obj;
	};
	this.bind = function(obj, conf){
		this._conf =conf;
		this._activeItem = conf.act;
		this.setParent(conf.parent);
		if(conf.id){
			this.setId(conf.id);
		};
		this.init(obj);
	};
	this.init = function(obj){	
		_super.init.apply(this, arguments);		
		this._tabbar = new TabBar(this.getConfData(),this._self.childNodes.length);
		this._tabbar.create(this._self);
		this.initActiveItem(this._activeItem);
		//this.setActiveItem(this._activeItem);
		this.addEventlisteners();	
	};
	this.dispose = function(){
		_super.dispose.apply(this);
	};
	this.getConfData = function(){
		var conf={};
		for(var i=0;i<this._self.childNodes.length;i++){
			conf[i] = this._self.childNodes[i].getAttribute("_tabname");
		}
		return conf;
	};
	this.addEventlisteners = function(){
		for(var i=0,len = this._tabbar._self.childNodes.length;i<len;i++){
			this.addListener(this._tabbar._self.childNodes[i], "tap", this, "setActiveItem");
		}
	};
	this.initActiveItem = function(actnum){
		for(var i = 0,len = this._tabbar._self.childNodes.length;i<len;i++){
			this._self.childNodes[i].style.display = "none";
			this._tabbar._self.childNodes[i].className = "caf-button caf-tabbutton";
		}
		this._tabbar._self.childNodes[actnum].className = "caf-button caf-tabbutton on";
		this._self.childNodes[actnum].style.display = "block";
	};
	this.setActiveItem = function(ev){
		for(var i = 0,len = this._tabbar._self.childNodes.length;i<len;i++){
			this._self.childNodes[i].style.display = "none";
			this._tabbar._self.childNodes[i].className = "caf-button caf-tabbutton";
		}
		ev.target.className = "caf-button caf-tabbutton on";
		this._self.childNodes[ev.target.getAttribute("_tabIndex")].style.display = "block";
		this._activeItem = ev.target.getAttribute("_tabIndex");
	};
});